package com.ruoyi.web.controller.certificates;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.system.domain.TemporaryStaffAccount;
import com.ruoyi.system.entity.PersonnelArchives;
import com.ruoyi.system.service.PersonnelArchivesService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 人员档案(PersonnelArchives)表控制层
 *
 * @author makejava
 * @since 2022-11-22 09:00:25
 */
@RestController
@RequestMapping("personnel/archives")
public class PersonnelArchivesController {
    /**
     * 服务对象
     */
    @Resource
    private PersonnelArchivesService personnelArchivesService;

    /**
     * 分页查询
     *
     * @param personnelArchives 筛选条件
     * @return 查询结果
     */
    @GetMapping("list")
    public TableDataInfo queryByPage(PersonnelArchives personnelArchives) {
        startPage();
        List<PersonnelArchives> list = personnelArchivesService.selectList(personnelArchives);
        return getDataTable(list);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<PersonnelArchives> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.personnelArchivesService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param personnelArchives 实体
     * @return 新增结果
     */
    @PostMapping("add")
    public ResponseEntity<PersonnelArchives> add(@Validated @RequestBody PersonnelArchives personnelArchives) {
        return ResponseEntity.ok(this.personnelArchivesService.insert(personnelArchives));
    }

    /**
     * 编辑数据
     *
     * @param personnelArchives 实体
     * @return 编辑结果
     */
    @PutMapping("edit")
    public ResponseEntity<PersonnelArchives> edit(@Validated @RequestBody PersonnelArchives personnelArchives) {
        return ResponseEntity.ok(this.personnelArchivesService.update(personnelArchives));
    }

    /**
     * 删除数据
     *
     * @param personnelArchives 主键
     * @return 删除是否成功
     */
    @DeleteMapping("delete")
    public ResponseEntity<Boolean> deleteById(@Validated @RequestBody PersonnelArchives personnelArchives) {
        return ResponseEntity.ok(this.personnelArchivesService.deleteById(personnelArchives.getId()));
    }

    /**
     * 设置请求分页数据
     */
    protected void startPage() {
        PageUtils.startPage();
    }

    /**
     * 响应请求分页数据
     */
    @SuppressWarnings({"rawtypes", "unchecked"})
    protected TableDataInfo getDataTable(List<?> list) {
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(HttpStatus.SUCCESS);
        rspData.setMsg("查询成功");
        rspData.setRows(list);
        rspData.setTotal(new PageInfo(list).getTotal());
        return rspData;
    }

}

